Internet Connection :-
Internet Connection class
public static String getResponseString(String requestURL) {
URL url;
String response = "";
try {
url = new URL(requestURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(35000);
conn.setConnectTimeout(35000);
/*conn.setReadTimeout(100);
conn.setConnectTimeout(100);*/
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
int responseCode=conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
String line;
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line=br.readLine()) != null) {
response+=line;
}
}
else
{
response="";
}
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
public static final ProgressDialog getProgressDialog(Context context, String dialogMessage) {
final ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(false);
progressDialog.setMessage(dialogMessage);
return progressDialog;
}
public static void RedirectToActivity(Activity yourActivity, Class SecondActivity,
boolean isfinish, Bundle b)
{
Intent intent = new Intent(yourActivity, SecondActivity);
if (b != null)
intent.putExtras(b);
yourActivity.startActivity(intent);
yourActivity.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
if (isfinish) {
yourActivity.finish();
}
}
public static Dialog setDialog(Context context) {
dialog = new Dialog(context);
dialog.setCancelable(false);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_loading);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
return dialog;
}
Async Class
package app.googlemap.Response;
import android.os.AsyncTask;
import android.util.Log;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import app.googlemap.activity.GoogleApi;
public class BackgroudAsyn extends AsyncTask